<?php

/**
 * Created by PhpStorm.
 * Author: ls
 * Time: 2023/8/7 10:58
 * Desc:取消积分使用
 */
class Listener_Order_Refunded_Jifen extends Listener_Base
{
    public function handle($args)
    {
        $self       = new self();
        $self->args = $args;
        //判断队列是否开启,如果开启则把任务推送到队列
        if ($self->queue_status) {
            //推送到队列执行
            Queue::in('default', Listener_Order_Refunded_Jifen::class, $args);
        } else {
            $self->perform();
        }
    }

    public function perform()
    {
        $args    = $this->args;
        $ordersn = $args['ordersn'];
        $order   = DB::select()->from('member_order')
            ->where('ordersn', '=', $ordersn)
            ->execute()
            ->current();

        if ($order && $order['jifentprice'] > 0) {
            Model_Member_Jifen::order_back_jifen($order);
            St_Log::write('取消积分', array('ordersn' => $ordersn), 'event/order_refunded/log');
        }
    }
}